import 'package:appflutterhomeschool/model/templates_model.dart';
import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/general_page_jump_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/view_model/notice/custum_notifications_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/6/20
///邮箱： 1037438704@qq.com
///功能： 0 自定义创建通知 1，讨论 2，任务  3，信件页面  的信件页面 4,发布作业
class CustumNotificationsPage extends StatefulWidget {
  final int pageTag;
  final TemplatesModel templatesModel;

  CustumNotificationsPage({this.pageTag, this.templatesModel});

  @override
  _CustumNotificationsPageState createState() =>
      _CustumNotificationsPageState();
}

class _CustumNotificationsPageState extends State<CustumNotificationsPage> {
  @override
  Widget build(BuildContext context) {
    return ProviderWidget<CustumNotificationsViewModel>(
      model: CustumNotificationsViewModel(context,
          pageTag: widget.pageTag, templatesModel: widget.templatesModel),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        return GestureDetector(
          onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
          child: Scaffold(
            backgroundColor: Colors.white,
            appBar: MyAppBar2(title: viewModel.titleBar),
            body: Stack(
              children: <Widget>[
                Positioned(
                  left: 0,
                  right: 0,
                  top: 0,
                  bottom: widget.pageTag == 4
                      ? ScreenUtil().setWidth(115)
                      : ScreenUtil().setWidth(229),
                  child: SingleChildScrollView(
                    child: Column(
                      children: <Widget>[
                        AddresseeWidget(
                          page: widget.pageTag,
                          addressee: viewModel.student,
                          onTap: () => viewModel.initEvent(0),
                        ),
                        ReplyTitleWidget(
                            leftTitle: widget.pageTag == 4 ? "作业标题" : null,
                            textEditingController: viewModel.titleText),
                        //时间表  讨论的时候 显示出来
                        viewModel.dataItemWidget(),
                        Visibility(
                          visible: widget.pageTag == 4,
                          child: GeneralPageJumpWidget(
                            title: "点击添加系统推荐作业",
                            rightContent: viewModel.rightContent,
                            onTap: () => viewModel.initEvent(1),
                          ),
                        ),
                        ReplyInputBox(
                            textEditingController: viewModel.textContent),
                        //列表数据
                        ListViewWidget(
                          listImage: viewModel.imageUrlList ?? [],
                          onTapIndex: (index) {
                            viewModel.imageUrlList.removeAt(index);
                            setState(() {});
                          },
                        ),
                        //放一添加图片  新建任务的时候展示出来
                        viewModel.pictureItemWidget(),
                      ],
                    ),
                  ),
                ),
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Column(
                    children: <Widget>[
                      Visibility(
                        visible: viewModel.receivingConfirmation,
                        child: Container(
                          decoration: BoxDecoration(
                              border: Border(
                                  top: BorderSide(
                                      width: 0.3, color: Colors.grey[200]))),
                          margin: EdgeInsets.only(
                              left: ScreenUtil().setWidth(31),
                              right: ScreenUtil().setWidth(31)),
                          height: ScreenUtil().setWidth(114),
                          child: GestureDetector(
                            onTap: () {
                              viewModel.agreeBool = !viewModel.agreeBool;
                              setState(() {});
                            },
                            child: Row(
                              children: <Widget>[
                                Icon(
                                    viewModel.agreeBool
                                        ? Icons.check_circle
                                        : Icons.panorama_fish_eye,
                                    size: ScreenUtil().setWidth(38),
                                    color: viewModel.agreeBool
                                        ? Colors.blue
                                        : Colors.grey),
                                SizedBox(width: 5),
                                Text("需要接收人确认", style: TextStyles.textGray37)
                              ],
                            ),
                          ),
                        ),
                      ),
                      ButtonWidget().rectangleButtonWidget(
                          buttonName: "发布", onPressed: viewModel.releaseOnTap),
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      },
    );
  }
}
